package com.ding.easycontroller.helper;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class EcRequestImpl extends HttpServletRequestWrapper implements EcRequest {

    public EcRequestImpl(HttpServletRequest request) {
        super(request);
    }

    @Override
    public String getRequestURI() {
        String v = super.getRequestURI();
        try {

            if (v == null) {
                return null;
            }

            return URLDecoder.decode(v, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            return v;
        }
    }


    @Override
    public StringBuffer getRequestURL() {
        StringBuffer requestURL = super.getRequestURL();
        try {

            if (requestURL == null) {
                return null;
            }

            return new StringBuffer(URLDecoder.decode(requestURL.toString(), "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            return requestURL;
        }
    }

    @Override
    public String getPathInfo() {
        String v = super.getPathInfo();
        try {
            if (v == null) {
                return null;
            }
            return URLDecoder.decode(v, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            return v;
        }
    }


}
